<template>
    <div class="index_service">
       <div class="prev-arrow" @tap="handlePrev" :style="{color:app_tabBar.config.secondcolor}"><i-icon type="return" size="40" /></div>
        <swiper :current="current" class="list" :style="'height:'+(imgHeights[current]+214)+'rpx'" @change="imageChange" circular="true">
            <block v-for="item in data.list" :key="item.id">
                <swiper-item class="slide-item">
                    <div class="body">
                        <figure>
                          <image :src="item.columnimg" mode="widthFix" @load="imageLoad" class="slide-image" :style="'height:'+imgHeights[current]+'rpx;width:100%;'"/>
                        </figure>
                        <div class="content">
                            <div class="title" :style="{color:app_tabBar.config.firstcolor}">{{item.name}}</div>
                            <p :style="{color:app_tabBar.config.secondcolor}">{{item.description}}</p>
                        </div>
                    </div>
                </swiper-item>
            </block>
        </swiper>
        <div class="next-arrow" @tap="handleNext" :style="{color:app_tabBar.config.secondcolor}"><i-icon type="enter" size="40" /></div>
    </div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
  props: {
    data: Array
  },
    computed: {
    ...mapGetters(['app_tabBar'])
  },
  data() {
    return {
      imgHeights: [],
      current: 0
    }
  },
  methods: {
    imageLoad(e) {
      const imgwidth = e.mp.detail.width
      const imgheight = e.mp.detail.height
      const ratio = imgwidth / imgheight
      this.ratio = ratio
      const viewHeight = 590 / ratio
      this.imgHeights.push(viewHeight)
    },
    imageChange(e) {
      this.current = e.mp.detail.current
    },
    handlePrev() {
      const current = this.current
      this.current = current > 0 ? current - 1 : this.data.list.length - 1
    },
    handleNext() {
      const current = this.current
      this.current = current < this.data.list.length - 1 ? current + 1 : 0
    }
  }
}
</script>
<style lang="scss" scoped>
.index_service {
  position: relative;
  .fa {
    font-size: 40px;
    color: #a6a6a6;
    opacity: 0.5s;
  }
  .prev-arrow {
    position: absolute;
    top: 50%;
    left: -8px;
    transform: translateY(-50%);
  }
  .next-arrow {
    position: absolute;
    top: 50%;
    right: -8px;
    transform: translateY(-50%);
  }
  .list {
    margin: 0 25px;
  }
  .slide-item {
    .content {
      .title {
        overflow: hidden;
        text-shadow: none;
        font-size: 16px;
        height: 46px;
        line-height: 46px;
        color: #000000;
        transition: all 0.66s cubic-bezier(0.17, 0.84, 0.44, 1);
        border-bottom: 1px solid #e1e1e1;
        text-align: left;
        width: 100%;
        position: relative;
        &:before {
          position: absolute;
          content: '';
          width: 10px;
          height: 1px;
          background-color: #000000;
          background-color: #000000;
          bottom: 0;
          -webkit-transition: all 0.66s cubic-bezier(0.17, 0.84, 0.44, 1);
          transition: all 0.66s cubic-bezier(0.17, 0.84, 0.44, 1);
        }
      }
      p {
        color: #999999;
        font-size: 13px;
        line-height: 24px;
        height: 50px;
        overflow: hidden;
        width: 100%;
        margin-top: 10px;
        margin-bottom: 14px;
        text-align: left;
      }
    }
  }
}
</style>